using UnityEngine;

namespace Exploder.Demo
{
	public class GrenadeController : MonoBehaviour
	{
		public AudioClip Throw;

		public AudioSource Source;

		public GrenadeObject Grenade;

		public Camera MainCamera;

		private float explodeTimer;

		private float throwTimer;

		private bool exploding;

		private void Start()
		{
			throwTimer = float.MaxValue;
			explodeTimer = float.MaxValue;
			exploding = false;
		}

		private void Update()
		{
			if (UnityEngine.Input.GetKeyDown(KeyCode.G) && !exploding)
			{
				throwTimer = 0.4f;
				Source.PlayOneShot(Throw);
				explodeTimer = 2f;
				exploding = true;
				Grenade.Throw();
				ExploderUtils.SetVisible(base.gameObject, status: false);
			}
			throwTimer -= Time.deltaTime;
			if (throwTimer < 0f)
			{
				throwTimer = float.MaxValue;
				ExploderUtils.SetVisible(Grenade.gameObject, status: true);
				ExploderUtils.SetActive(Grenade.gameObject, status: true);
				Grenade.transform.position = base.gameObject.transform.position;
				Grenade.GetComponent<Rigidbody>().velocity = MainCamera.transform.forward * 20f;
			}
			explodeTimer -= Time.deltaTime;
			if (explodeTimer < 0f)
			{
				Grenade.Explode();
				explodeTimer = float.MaxValue;
			}
			if (Grenade.ExplodeFinished)
			{
				exploding = false;
				ExploderUtils.SetVisible(base.gameObject, status: true);
			}
		}
	}
}
